package com.example.demo.conflg;

import com.example.demo.common.AppValues;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 登录页面的拦截器
 */
public class LoginHandlerConflg implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session =request.getSession(false);
        if(session==null||session.getAttribute(AppValues.USER_KEY)==null) { //判断是否登录
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
